export default {
    methods:{
        //将服务端返回的JSON结构，构造表单的数据结构。
        getFormJsonByBoJson(boJson){
            let result={};
            let attrList=[];
            let attrs=boJson.boAttrList;
            let ents=boJson.boEntityList;
            for(let i=0;i<attrs.length;i++){
                let attr=attrs[i];
                let field=this.getBoAttr(attr);
                attrList.push(field);
            }
            for(let i=0;i<ents.length;i++){
                let ent=ents[i];
                let subEnt=this.getSubEnt(ent);
                attrList.push(subEnt);
            }
            result.boAttrList=attrList;
            return result;
        },
        //简化字段属性数据
        getBoAttr(field){
            if(!field){
                return {};
            }
            var obj = {
                name: field.name,
                comment: field.comment,
                fieldName: field.fieldName,
                control: field.control,
                isSingle: field.isSingle,
                langJsonVal:field.langJsonVal
            }
            return obj;
        },
        //简化子表属性数据
        getSubEnt(subEnt){
            var obj = {
                alias: subEnt.alias,
                name: subEnt.name,
                tableName: subEnt.tableName,
                idField: subEnt.idField,
                //onetoone,onetomany
                type:subEnt.boRelation.type,
                pattern:'block',
                langJsonVal:subEnt.langJsonVal
            }
            var boAttrList=[];
            for (let i = 0; i < subEnt.boAttrList.length; i++) {
                boAttrList.push(this.getBoAttr( subEnt.boAttrList[i]));
            }
            obj["boAttrList"]=boAttrList;
            var boEntityList=[];
            for (let i = 0; i < subEnt.boEntityList.length; i++) {
                boEntityList.push(this.getSubEnt( subEnt.boEntityList[i]));
            }
            obj["boEntityList"]=boEntityList;

            return obj;
        }
    }
}